<?php
    $sql = "select * from categories c inner join categories_description cd on c.categories_id = cd.categories_id where parent_id = 0 and cd.language_id = '" . (int) $languages_id . "'";
    $category_query = tep_db_query($sql);
    while ($category = tep_db_fetch_array($category_query)) {
        $super_categories[] = $category;
    }
    // Measure margin left for active menu item
    $margin_left = 0;
    for ($i = 0, $n = sizeof($super_categories); $i < $n; $i++) {
        if ($super_categories[$i]['categories_id'] == $super_parent_category_id) {
            $margin_left = $i*14.28;
            break;
        }
    }
?>
<div class="seperator1">
    <?php
        if($super_parent_category_id > 0) {
            echo '<div class="current-item" style="margin-left: '.$margin_left.'%;"></div>';
        }
    ?>
</div>
<div class="menubar">
    <ul id="nav" class="dropdown dropdown-linear dropdown-columnar">
        <?php
        $itemPerColumn = 4;
        for ($i = 0, $n = sizeof($super_categories); $i < $n; $i++) {
            $columnNo = 0;
            $category = $super_categories[$i];
            $needCreateSubItem = true;
            $needCreateColumn = true;
            echo '<li class="navItem item' . ($i + 1) . '"><div class="navItemHover item' . ($i + 1) . '"></div><a href="' . tep_href_link('index.php', 'cPath=' . $category['categories_id']) . '">' . $category["categories_name"] . '</a>'; //$category['categories_name'];
            $sql_supcat = "select * from categories c inner join categories_description cd on c.categories_id = cd.categories_id where parent_id =" . $category['categories_id'] . "  and cd.language_id = '" . (int) $languages_id . "'";
            $sub_category_query = tep_db_query($sql_supcat);
            while ($sub_category = tep_db_fetch_array($sub_category_query)) {
                if ($needCreateSubItem) {
                    echo '<ul class="content">';
                    $needCreateSubItem = false;
                }
                if ($columnNo % $itemPerColumn == 0) {
                    // End column
                    if (!$needCreateColumn) {
                        echo '</ul>';
                        echo '</li>';
                    }
                    $needCreateColumn = true;
                }
                $columnNo++;
                // Begin column
                if ($needCreateColumn) {
                    $needCreateColumn = false;
                    echo '<li class="dir">';
                    echo '<ul class="column">';
                }
                echo '<li><a href="' . tep_href_link('index.php', 'cPath=' . $category['categories_id'] . '_' . $sub_category['categories_id']) . '">' . $sub_category["categories_name"] . '</a></li>';
            }
            // End column
            if (!$needCreateColumn) {
                echo '</ul>';
                echo '</li>';
            }
            if (!$needCreateSubItem) {
                echo '</ul>';
            }
            $needCreateSubItem = false;
            echo '</li>';
        }
        ?>

        <li class="navItem item6"><div class="navItemHover item6"></div><a href="<?php echo tep_href_link(FILENAME_SHOPPING_CART); ?>">ĐẶT HÀNG</a>
        </li>
        <li class="navItem item7"><div class="navItemHover item7"></div><a href="<?php echo tep_href_link('contact.php') ?>">LIÊN HỆ</a>
        </li>
    </ul>
</div>
<div class="seperator2"></div>